package com.bys.admin.system.controller;


import com.bys.response.R;
import com.bys.admin.system.entity.SysRole;
import com.bys.admin.system.service.ISysRoleService;


import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author bys
 * @since 2023-06-26
 */
@Tag(name = "角色接口")
@RestController
@RequestMapping("/system/sys-role")
public class SysRoleController {
    @Resource
    private ISysRoleService sysRoleService;
    @Operation(summary="列表查询角色")
    @GetMapping(value = "/simple-list")
    public R<List<SysRole>> simpleList(){
        List<SysRole> data = sysRoleService.list();
        return R.success(data);
    }
    @Operation(summary="列表查询角色")
    @GetMapping(value = "/list")
    public R<List<SysRole>> list(SysRole sysRole){
        List<SysRole> data = sysRoleService.list();
        return R.success(data);
    }
    @Transactional(rollbackFor = Exception.class)
    @Operation(summary="保存系统角色")
    @PostMapping("/save")
    public R save(@RequestBody SysRole sysRole){
        sysRole.setCreateBy(1L);
        sysRoleService.save(sysRole);
        return R.success();
    }
    @Transactional(rollbackFor = Exception.class)
    @Operation(summary="修改系统角色")
    @PostMapping("/update")
    public R update(@RequestBody SysRole sysRole){
        sysRole.setUpdateBy(1L);
        sysRole.setUpdateTime(LocalDateTime.now());
        sysRoleService.updateById(sysRole);
        return R.success();
    }


}
